package com.inlycat.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.inlycat.entity.Barrage;
import com.inlycat.service.BarrageService;

/**
 * @author jarvan4dev@163.com
 * @since 2015年8月24日下午3:01:44
 * @category
  
 **/
@Controller
@RequestMapping("/barrage")
public class BarrageController {

	private static final Logger logger = LoggerFactory
			.getLogger(BarrageController.class);
	
	@Resource
	private BarrageService barrageService;

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add(Barrage barrage) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		boolean result = barrageService.add(barrage);
		if (result) {
			resultMap.put("code", 1);
			resultMap.put("message", "success");
			logger.info("message","success");
		} else {
			resultMap.put("code", 0);
			resultMap.put("message", "弹幕发送失败");
			logger.info("message","弹幕发送失败，请检查原因");
		}
		return resultMap;
	}

	@RequestMapping(value = "/select", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> select(Barrage barrage) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<Barrage> barrages = barrageService.select(barrage);
		if (barrages == null||barrages.size()==0) {
			resultMap.put("code", 0);
			resultMap.put("message", "暂无弹幕");
		} else {
			resultMap.put("code", 1);
			resultMap.put("message", "success");
			resultMap.put("data", barrages);
		}
		return resultMap;
	}
}
